/*
4：传闻StringBuilder比StringBuffer快,
比较一下，输出你的比较结果（拼接10万个相同的字符串，比较时间）。
*/
package Work0524;

public class Compare {

	public static void main(String[] args) {
		long a = System.nanoTime();
		StringBuilder one = new StringBuilder("");
		for (int z = 1; z <= 100000; z++) {
			one = one.append("黑猪");
		}
		long a1 = System.nanoTime();
		long a2 = a1 - a;
		System.out.println(a2);

		long b = System.nanoTime();
		StringBuffer two = new StringBuffer("");
		for (int y = 1; y <= 100000; y++) {
			two = two.append("黑猪");
		}
		long b1 = System.nanoTime();
		long b2 = b1 - b;
		System.out.println(b2);

		System.out.println(a2 > b2 ? "StringBuilder快" : "StringBuffer快");
	}

}
